<template>
  <van-row>
    <van-search
      v-model="keyword"
      shape="round"
      show-action
      placeholder="请输入搜索关键词"
      @search="onSearch"
      @cancel="onCancel"
    />
  </van-row>
</template>

<script>

export default {
  name: 'QueryPage',
  data() {
    return {
      keyword: ''
    }
  },
  mounted() {
    const keyword = this.$route.query.keyword
    if (keyword) {
      this.keyword = keyword
    }
  },
  methods: {
    onSearch() {
      const to = this.$route.query.from
      if (to) {
        this.$router.push(to + '?keyword=' + this.keyword)
      } else {
        this.$router.push('/')
      }
    },
    onCancel() {
      const to = this.$route.query.from
      if (to) {
        this.$router.push(to)
      } else {
        this.$router.push('/')
      }
    }
  }
}
</script>

<style scoped>

</style>
